package bairui.international.console.web.controller.index.roll;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.lianjing.sh.model.uml.model.status.State_UpDown;
import com.lianjing.sh.project.commons.util.Util_FileDeal;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.sh_lianjing.util.Util_BeanCopyByDeclaredProperties;

import bairui.international.model.domain.jpa.TB_IndexRollImage;
import bairui.international.service.Service_IndexRollImage;

/**
 *
 * 滚动图片管理
 *
 * @generated
 * 
 * @see STest_C_Index_Roll_RollManage_FileUpload 测试
 *
 */
@Controller
public class C_Index_Roll_RollManage_FileUpload
 extends SC_Index_Roll_RollManage_FileUpload 
{
	
	@Autowired private Service_IndexRollImage service_IndexRollImage;
	
	/**
	 * 上传文件
	 */
	@Action(FileUpload.class)
	@PostMapping(FileUpload.RequestMappingValue)
	public @FomatOutput @ResponseBody Object fileUpload(
		@Valid Input_FileUpload_Input_Upload.Model input
	) throws Exception {
		for(MultipartFile item : input.getFileUrlFile()){
			TB_IndexRollImage bean = new TB_IndexRollImage();
			// 上传文件相关
			Util_FileDeal
				.saveFile(item, pathConfig.getPosition_Image_IndexRoll())
				.resultTo(bean);
			// 保存数据
			TB_IndexRollImage save = Util_BeanCopyByDeclaredProperties.copyProperties(input, bean);
				save.setState(State_UpDown.Draft);
			service_IndexRollImage.save(save);
		}
		return null;
	}
	

}
